<?php
session_start();
for ($i = 0; $i < 4; $i++) {
	$rand .= dechex(rand(1, 15));
}
//将随机数存入session
$_SESSION["rand"] = $rand;
//产生一个画布
$im = imagecreatetruecolor(45, 17);
// 背景色
$background = imagecolorallocate($im, 0x9d, 0xc1,0xfd );
//随机的字符串颜色
$textcolor = imagecolorallocate($im, 255, 0, 0);
//填充背景色
imagefill($im, 0, 0, $background);
//产生随机的干扰像素点
for ($j = 0; $j < 200; $j++) {
	$randColor = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
	imagesetpixel($im, rand(0,45), rand(0,17), $randColor);
}
//将字符串加入到图片中,位置随机
imagestring($im, 5, rand(0,10), rand(0,3), $rand, $textcolor);
header("Content-type: image/jpeg");
imagejpeg($im);
imagedestroy($im);

?>